﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MarioMapEditor
{
    class TreeClipping
    {
        public static AABB clipRECT(AABB OB1, AABB OB2)
        {

            AABB temp;
            temp.top    = 0;
            temp.left   = 0;
            temp.right  = 0;
            temp.bot    = 0;

            if (!checkCollision(OB1, OB2))
            {
                return temp;
            }

            if (OB1.top > OB2.top) temp.top = OB2.top;
            else temp.top = OB1.top;

            if (OB1.bot > OB2.bot) temp.bot = OB1.bot;
            else temp.bot = OB2.bot;

            if (OB1.left > OB2.left) temp.left = OB1.left;
            else temp.left = OB2.left;

            if (OB1.right > OB2.right) temp.right = OB2.right;
            else temp.right = OB1.right;

            return temp;
        }

        public static bool checkCollision(AABB OB1, AABB OB2)
        {
            if (OB1.bot >= OB2.top) return false;
            if (OB2.bot >= OB1.top) return false;
            if (OB1.left >= OB2.right) return false;
            if (OB2.left >= OB1.right) return false;
            return true;
        }
    }
}
